package com.cloud.utils;

import java.util.HashMap;
import java.util.Map;

/**
 * token解析类
 *
 * @Author yangyuwei
 * @Date 2022/4/1
 * @Param
 * @Return
 **/
public class BaseContextUtil {

    public static ThreadLocal<Map<String, Object>> threadLocal = new ThreadLocal<Map<String, Object>>();

    public static void set(String key, Object value) {
        Map<String, Object> map = threadLocal.get();
        if (map == null) {
            map = new HashMap<String, Object>();
            threadLocal.set(map);
        }
        map.put(key, value);
    }

    public static <T> T get(String key) {
        Map<String, Object> map = threadLocal.get();
        if (map == null) {
            map = new HashMap<String, Object>();
            threadLocal.set(map);
        }
        T obj = (T) map.get(key);
        return obj;
    }


    public static void remove() {
        threadLocal.remove();
    }

}
